/*
 * WantToBuyDetailOfferListItem.java
 * business
 *
 * Created by chentao on 2017/5/12.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;

import com.yidiandao.business.R;
import com.yidiandao.business.data.OfferEntity;
import com.yidiandao.business.data.event.DeletePostedWantBuyEvent;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.MyAskToBuyDetailOfferHolder;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.UIUtils;

import org.greenrobot.eventbus.EventBus;

/**
 * 个人中心-求购详情-报价信息
 * <p>
 * Created by ChenTao(chentao7v@gmail.com) on 2017/5/12 0012 16:06
 */
public class MyAskToBuyDetailOfferListItem extends DisplayListItem<MyAskToBuyDetailOfferHolder, OfferEntity> {

    public MyAskToBuyDetailOfferListItem(OfferEntity s) {
        super(s);
    }

    @Override
    public void onShow(Context context, MyAskToBuyDetailOfferHolder holder) {
        ImageLoader.loadAvatar(context, holder.mIvAvatar, data.getSex());
        holder.mTvShopName.setText(data.getDpName());
        holder.mTvPhone.setText(data.getMobile());
        holder.mTvTip.setVisibility(data.getIsNew().equals("1")? View.VISIBLE:View.GONE);
        holder.mTvPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri = Uri.parse("tel:" + data.getMobile());
                Intent intent = new Intent(Intent.ACTION_DIAL, uri);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                UIUtils.getContext().startActivity(intent);
            }
        });
        holder.mTvAccept.setVisibility(data.getCanAccept()==1?View.VISIBLE:View.GONE);
        holder.mTvAccept.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new DeletePostedWantBuyEvent(data.getOfferId()));
            }
        });
        holder.mTvGoodsPrice.setText(UIUtils.getString(R.string.ask_to_buy_detail_goods_price,data.getPrice(),data.getUnit()));
        holder.mTvLogisticsPrice.setText(UIUtils.getString(R.string.ask_to_buy_detail_logistic_price,data.getShippingFee(),data.getUnit()));

    }

    @Override
    public String getDisplayItemTag() {
        return MyAskToBuyDetailOfferListItem.class.getSimpleName();
    }

    @Override
    public Class<MyAskToBuyDetailOfferHolder> getViewHolderClazz() {
        return MyAskToBuyDetailOfferHolder.class;
    }
}
